MonitorTabView = function(tab){
	this.tab = tab;
	this.view = tab.tab;
	this.divId="tab_div";
	this.navType = "tabs";
};

MonitorTabView.prototype = {
	
	/* 装载数据 */
	load:function(){
		this.remove();
		$('#'+this.divId).append(this.getDiv());
	},
	
	/* 获取总DIV */
	getDiv:function(){
		var div = "";
		div += "<div class='grid_3 grid_5'>";
		div += "<div class='but_list'>";
		div += "<div class='bs-example bs-example-tabs' role='tabpanel' data-example-id='togglable-tabs'>";
		
		div += this.getTabData();
		
		div += this.getContentData();
		
		div += "</div>";
		div += "</div>";
		div += "</div>";
		return div;
	},
	
	/* 获取标签数据信息 */
	getTabData:function(){
		var data = "";
		
		//标签页形式
		if(this.navType == "tabs"){
			data += "<ul id='myTab' class='nav nav-tabs' role='tablist'>";
		}else{
			data += "<ul id='myTab' class='nav nav-pills' role='tablist'>";
		}
		
		var first = true;
		
		for(var i=0;i<this.view.length;i++){
				
			//无下拉信息
			if(this.view[i].child.length == 0){
				if(first){
					data += "<li role='presentation' class='active'>";
					first = false;
				}else{
					data += "<li role='presentation'>";
				}
				
				data += "<a href='#"+this.view[i].id+"' id='"+this.view[i].id+"-tab' role='tab' data-toggle='tab' aria-controls='"+this.view[i].id+"' aria-expanded='true'>" +
						this.view[i].lable +
						"</a>";
				data += "</li>";
			}
			
			//存在下拉信息
			else{
				if(first){
					data += "<li class='dropdown active'>";
				}else{
					data += "<li class='dropdown'>";
				}
				data += "<a href='#' id='"+this.view[i].id+"' class='dropdown-toggle' data-toggle='dropdown'>";
				data += this.view[i].lable;
				data += " <b class='caret'></b>";
				data += "</a>";
				data += "<ul class='dropdown-menu' role='menu' aria-labelledby='"+this.view[i].id+"'>";
				for(var j=0;j<this.view[i].child.length;j++){
					if(first){
						data += "<li class='active'>";
						first = false;
					}else{
						data += "<li>";
					}			
					data += "<a href='#"+this.view[i].child[j].id+"' tabindex='-1' data-toggle='tab'>";
					data += this.view[i].child[j].lable;
					data += "</a></li>";
				}
				data += "</ul>";
				data += "</li>";
			}
			
		}
		
		data += "</ul>"
		
		return data;
	},
	
	/* 获取内容数据信息 */
	getContentData:function(){
		var content = "";
		
		content += "<div id='myTabContent' class='tab-content'>";
		
		var first = true;
		
		for(var i=0;i<this.view.length;i++){
			
			//无下拉信息
			if(this.view[i].child.length == 0){
				
				if(first){
					content += "<div role='tabpanel' class='tab-pane fade in active' id='"+this.view[i].id+"' aria-labelledby='"+this.view[i].id+"-tab'>";
					first = false;
				}else{
					content += "<div role='tabpanel' class='tab-pane fade' id='"+this.view[i].id+"' aria-labelledby='"+this.view[i].id+"-tab'>";				
				}
				
				content += "</div>";
				
			}
			
			//存在下拉信息
			else{
				
				for(var j=0;j<this.view[i].child.length;j++){
					
					if(first){
						content += "<div role='tabpanel' class='tab-pane fade in active' id='"+this.view[i].child[j].id+"' aria-labelledby='"+this.view[i].child[j].id+"-tab'>";
						first = false;
					}else{
						content += "<div role='tabpanel' class='tab-pane fade' id='"+this.view[i].child[j].id+"' aria-labelledby='"+this.view[i].child[j].id+"-tab'>";				
					}
					
					content += "</div>";				
				}			
			}
			
		}
				
		return content;
	},
	
	/* 刷新数据 */
	refresh:function(){
		this.load();
	},
	
	/* 移除数据 */
	remove:function(){
		$("#"+this.divId+" div").remove();
	},
	
	/* 设置DIV标示 */
	setDivId:function(divId){
		this.divId = divId;
	},
	
	/* 设置标签页形式 */
	setNavType:function(navType){
		this.navType = navTyep;
	}
	
};